<?php
require_once('core.php');
if($_GET['table'] == 'customers'){
	$sql = 'SELECT * FROM customers WHERE name LIKE "'.$_GET['term'].'%"';
	$q = mysql_query($sql);
	$first = false;
	while($rs = mysql_fetch_assoc($q)){
		if($first){
			$s .= ', "'.$rs['name'].' โทร. '.$rs['mobile'].'"';
			if($rs['store_name'] != ""){
				$s .= ', "'.$rs['store_name'].' โทร. '.$rs['mobile'].'"';
			}
		}else{
			$s .= '"'.$rs['name'].' โทร. '.$rs['mobile'].'"';
			$first = true;
		}
	}
	echo '[ '.$s.' ]';
}

if($_GET['table'] == 'products'){
	$sql = 'SELECT * FROM products WHERE name LIKE "'.$_GET['term'].'%"';
	$q = mysql_query($sql);
	$first = false;
	while($rs = mysql_fetch_assoc($q)){
		if($first){
			$s .= ', "'.$rs['name'].'"';
		}else{
			$s .= '"'.$rs['name'].'"';
			$first = true;
		}
	}
	echo '[ '.$s.' ]';
}
?>

